/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package folderManager;

import java.io.File;
import java.util.Arrays;
import java.util.List;

/**
 *
 * @author Allan
 */
public abstract class FolderManager
{   
    /**
     * Kontrollerer on mappen/mapperne eksisterer, eksisterer de ikke så oprettes de.<br />
     * Den String der kommer med skal indeholde mappenavnene, i den rækkefølge de skal oprettes i og adskildt af / <br />
     * Eks.: "mappe1/mappe2/mappe3"
     * @author Allan Andersen
     * @param String str
     * @return String returnPath
     */
    public static String checkAndCreateFolder(String str)
    {
        List<String> folderList;
        folderList = Arrays.asList(str.split("/"));

        String missingFolder;
        missingFolder = "";
        
        String returnPath;
        returnPath = "";
        
        boolean running;
        running = false;
        
        int listSize;
        listSize = folderList.size();
        
        int maxCount;
        maxCount = listSize + 1;
        
        String[] arrFolders;
        arrFolders = new String[maxCount];
        
        arrFolders[0] = "BejerholmStenhuggeri_Documents";
        
        int i;
        i = 1;
        
        for(String list : folderList)
        {
            arrFolders[i] = list;
            
            i++;
        }
        
        while(!running) // Så længe der står false i running kører denne
        {        
            missingFolder = folderManager.FolderHandler.checkForFolder(arrFolders);

            if(!"".equals(missingFolder))
            {
                folderManager.FolderControl.createFolder(missingFolder);
            }
            else
            {
                running = true;
                returnPath = System.getProperty("user.home") + File.separatorChar + "Dokumenter";
                
                for(String value : arrFolders)
                {
                    returnPath = returnPath + "\\" + value;
                }
            }
        }
        
        return returnPath;
    }
}
